// import 'dart:html';

import 'dart:ui';
import 'package:flutter_bmfmap_example/config/http_options.dart';
import 'package:flutter_bmfmap_example/service/marketservice.dart';
import 'package:url_launcher/url_launcher.dart';
import 'package:flutter/material.dart';

class PayPage extends StatefulWidget {
  PayPage({Key key, this.id}) : super(key: key);

  String id;
  @override
  _PayPageState createState() => _PayPageState();
}

class _PayPageState extends State<PayPage> {
  bool select = true;

  var orderinfo;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    _getOrderinfo();
  }

  Future<void> _getOrderinfo() async {
    orderinfo = await Marketservice.getOrederById(widget.id);
    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    if (orderinfo == null) {
      return Scaffold(
        body: Center(child: CircularProgressIndicator()),
      );
    } else {
      return Scaffold(
        appBar: AppBar(
          title: Text('巢收银台'),
          centerTitle: true,
        ),
        body: ListView(
          children: [
            SizedBox(height: 24),
            _buildprice(),
            _buildbody(),
          ],
        ),
        bottomSheet: Container(
          alignment: Alignment.center,
          color: Colors.white,
          height: 80,
          child: Padding(
            padding: const EdgeInsets.all(16.0),
            child: InkWell(
              onTap: () {
                _launchUrl();
              },
              child: Container(
                height: 40,
                decoration: BoxDecoration(
                  color: Color.fromRGBO(200, 36, 27, 1),
                  borderRadius: BorderRadius.circular(20),
                ),
                child: Center(
                  child: Text(
                    '确认支付￥${orderinfo['money']}',
                    style: TextStyle(
                        fontSize: 14,
                        color: Colors.white,
                        fontWeight: FontWeight.w500),
                  ),
                ),
              ),
            ),
          ),
        ),
      );
    }
  }

  _launchUrl() async {
    if (await canLaunch(
        HttpOptions.BASE_URL + '/alipay/create?orderId=${widget.id}')) {
      await launch(
          HttpOptions.BASE_URL + '/alipay/create?orderId=${widget.id}');
    } else {
      setState(() {
        // _status = 'Unable to launch url $url';
      });
    }
  }

  _buildbody() {
    return Padding(
      padding: const EdgeInsets.only(left: 16.0, right: 16, top: 16),
      child: Container(
        // height: 40,
        padding: const EdgeInsets.all(12.0),
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(10),
          boxShadow: [
            BoxShadow(
              color: Colors.grey[300],
              blurRadius: 2,
              spreadRadius: 0,
              offset: Offset(0, 1),
            )
          ],
        ),
        child: Column(
          children: [
            Row(
              children: [
                Image.asset(
                  'assets/images/icons/png/支付宝.png',
                  width: 24,
                ),
                SizedBox(width: 8),
                Text(
                  '支付宝',
                  style: TextStyle(color: Colors.black),
                ),
                Spacer(),
                Radio(
                  value: '支付宝',
                  groupValue: '支付宝',
                  activeColor: Colors.orangeAccent,
                  onChanged: (value) {
                    select = value;
                    print(value);
                  },
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }

  _buildprice() {
    return Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        Text('￥ ',
            style: TextStyle(
              fontSize: 14,
              fontWeight: FontWeight.w600,
              color: Color.fromRGBO(186, 36, 27, 1),
            )),
        Text(orderinfo['money'].toString(),
            style: TextStyle(
              fontSize: 26,
              fontWeight: FontWeight.w600,
              color: Color.fromRGBO(186, 36, 27, 1),
            )),
      ],
    );
  }
}
